package cn.hongwei.service.impl;

import cn.hongwei.feign.StockFeign;
import cn.hongwei.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.hongwei.pojo.Order;
import cn.hongwei.mapper.OrderMapper;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order>
    implements OrderService {

    @Autowired
    private StockFeign stockFeign;

    @GlobalTransactional
    @Override
    public void createOrder() {
        Order order = Order.builder().productId(9).status(0).totalAmount(100).build();
        baseMapper.saveOrder(order);

        //扣减库存
        stockFeign.reduce(order.getProductId());
        int i=1/0;
    }
}




